import java.util.Comparator;
import java.util.TreeSet;

public class Demo7 {
    //使用TreeSet 集合实现字符串按长度排序
    public static void main(String[] args) {

        TreeSet  <String> treeSet=new TreeSet<>(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                int n1=o1.length()-o2.length();
                int n2=o1.compareTo(o2);
                return n1==0?n2:n1;
            }
        });

        treeSet.add("helloworld");
        treeSet.add("jt");
        treeSet.add(("xjt"));
        treeSet.add("chs");
        treeSet.add("xchs");
        System.out.println(treeSet);
    }
}
